package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.json.JSONArray;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedRequest;
import com.zzyl.nursing.domain.DeviceDto;
import com.zzyl.nursing.vo.DeviceVo;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 设备维护表Controller
 * 
 * @author ruoyi
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/nursing/device")
@Slf4j
@Api(tags = "设备维护表的接口")
public class DeviceController extends BaseController
{
    @Autowired
    private IDeviceService deviceService;

    /**
     * 查询设备维护表列表
     */
    @ApiOperation("查询设备维护表列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(Device device)
    {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

    @PostMapping("/syncProductList")
    @ApiOperation("同步产品列表")
    public AjaxResult syncProductList() throws Exception {
        log.info("开始同步产品列表");
        deviceService.syncProductList();
        return AjaxResult.success();
    }

    @GetMapping("/allProduct")
    @ApiOperation("获取产品列表")
    public AjaxResult allProduct() {
       return success(deviceService.allProduct());
    }

    @PostMapping("/register")
    @ApiOperation("注册设备")
    public AjaxResult register(@RequestBody DeviceDto deviceDto) {
        log.info("开始注册设备");
        deviceService.register(deviceDto);
        return success();
    }


    /**
     * 获取设备详细信息
     */
    @PostMapping("/queryDeviceDetail")
    @ApiOperation("获取设备详细信息")
    public AjaxResult getInfo(@RequestBody DeviceVo deviceVo) {
        return success(deviceService.queryDeviceDetail(deviceVo));
    }


    @PostMapping("/queryThingModelPublished")
    @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    public AjaxResult queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request) throws Exception {
        return deviceService.queryThingModelPublished(request);
    }

    @PostMapping("/queryDevicePropertyStatus")
    public AjaxResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request){
        return deviceService.queryDevicePropertyStatus(request);
    }



//
//    /**
//     * 导出设备维护表列表
//     */
//    @ApiOperation("导出设备维护表列表")
//    @PreAuthorize("@ss.hasPermi('nursing:device:export')")
//    @Log(title = "设备维护表", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Device device)
//    {
//        List<Device> list = deviceService.selectDeviceList(device);
//        ExcelUtil<Device> util = new ExcelUtil<Device>(Device.class);
//        util.exportExcel(response, list, "设备维护表数据");
//    }
//
//    /**
//     * 获取设备维护表详细信息
//     */
//    @ApiOperation("获取设备维护表详细信息")
//    @PreAuthorize("@ss.hasPermi('nursing:device:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@ApiParam(value = "设备维护表ID", required = true)
//            @PathVariable("id") Long id)
//    {
//        return success(deviceService.selectDeviceById(id));
//    }
//
//    /**
//     * 新增设备维护表
//     */
//    @ApiOperation("新增设备维护表")
//    @PreAuthorize("@ss.hasPermi('nursing:device:add')")
//    @Log(title = "设备维护表", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@ApiParam(value = "设备维护表实体")
//            @RequestBody Device device)
//    {
//        return toAjax(deviceService.insertDevice(device));
//    }
//
//    /**
//     * 修改设备维护表
//     */
//    @ApiOperation("修改设备维护表")
//    @PreAuthorize("@ss.hasPermi('nursing:device:edit')")
//    @Log(title = "设备维护表", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@ApiParam(value = "设备维护表实体")
//            @RequestBody Device device)
//    {
//        return toAjax(deviceService.updateDevice(device));
//    }
//
//    /**
//     * 删除设备维护表
//     */
//    @ApiOperation("删除设备维护表")
//    @PreAuthorize("@ss.hasPermi('nursing:device:remove')")
//    @Log(title = "设备维护表", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(deviceService.deleteDeviceByIds(ids));
//    }
}
